#include<bits/stdc++.h>
using namespace std;
const int N = 100001;

int n;
int arr[N];
int brr[N],bp=0;

int main(){
    scanf("%d",&n);
    int num;
    for(int i=1;i<=n;i++){
        scanf("%d",&num);
        arr[num] = i;
    }
    int l,r,mid;
    for(int i=1;i<=n;i++){
        scanf("%d",&num);
        num = arr[num];
        if(bp==0||num>brr[bp-1]){
            brr[bp++]=num;
            continue;
        }
        l=0; r=bp-1;
        while(l<r){
            mid = (r-l)/2+l;
            if(num<brr[mid]){
                r=mid;
            }else{
                l=mid+1;  
            }
        }
        brr[l] = num;
    }
    printf("%d\n",bp);
    return 0;
}